/*
archer
Fox ratings and Trump tweets analyses
*/

* load foxratingstweets.dta

set scheme s1mono

***************
* create vars *
***************

gen time=mocount
gen timesquared=time*time 

gen jan=0
replace jan=1 if mocount==49|mocount==37|mocount==25|mocount==13|mocount==1
tab jan

gen feb=0
replace feb=1 if mocount==50|mocount==38|mocount==26|mocount==14|mocount==2
tab feb

gen mar=0
replace mar=1 if mocount==51|mocount==39|mocount==27|mocount==15|mocount==3
tab mar

gen apr=0
replace apr=1 if mocount==52|mocount==40|mocount==28|mocount==16|mocount==4
tab apr

gen may=0
replace may=1 if mocount==53|mocount==41|mocount==29|mocount==17|mocount==5
tab may

gen jun=0
replace jun=1 if mocount==54|mocount==42|mocount==30|mocount==18|mocount==6
tab jun

gen jul=0
replace jul=1 if mocount==43|mocount==31|mocount==19|mocount==7
tab jul

gen aug=0
replace aug=1 if mocount==44|mocount==32|mocount==20|mocount==8
tab aug

gen sep=0
replace sep=1 if mocount==45|mocount==33|mocount==21|mocount==9
tab sep

gen oct=0
replace oct=1 if mocount==46|mocount==34|mocount==22|mocount==10
tab oct

gen nov=0
replace nov=1 if mocount==47|mocount==35|mocount==23|mocount==11
tab nov

gen dec=0
replace dec=1 if mocount==48|mocount==36|mocount==24|mocount==12
tab dec

gen yr2017=0
replace yr2017=1 if year==2017
tab yr2017

* ratings: order in dataset is most recent years first
gen fncprimetime_lag=fncprimetimeratings811p[_n+1]
list mocount fncprimetimeratings811p fncprimetime_lag
gen fncprimetime_lag2=fncprimetimeratings811p[_n+2]

gen fncprimetime_change=fncprimetimeratings811p-fncprimetime_lag
tab fncprimetime_change

gen fncdaytime_lag=fnctotaldayviewers[_n+1]
list mocount fnctotaldayviewers fncdaytime_lag
gen fncdaytime_lag2=fnctotaldayviewers[_n+2]

gen fncdaytime_change=fnctotaldayviewers-fncdaytime_lag
tab fncdaytime_change

gen cnnprimetime_lag=cnnprimetimeratings[_n+1]
gen cnnprimetime_change = cnnprimetimeratings-cnnprimetime_lag

gen msnbcprimetime_lag = msnbcprimetimeratings[_n+1]
gen msnbcprimetime_change = msnbcprimetimeratings-msnbcprimetime_lag

gen cnndaytime_lag = cnntotaldayviewers[_n+1]
gen cnndaytime_change = cnntotaldayviewers-cnndaytime_lag

gen msnbcdaytime_lag = msnbctotaldayviewers[_n+1]
gen msnbcdaytime_change = msnbctotaldayviewers-msnbcdaytime_lag

* tweets
gen attack_bias_pct_lag=attack_bias_pct[_n+1]
list mocount attack_bias_pct attack_bias_pct_lag
list year month attack_bias_pct attack_bias_pct_lag

gen appearance_pct_lag=appearance_pct[_n+1]
list year month appearance_pct appearance_pct_lag

gen praise_pct_lag=praise_pct[_n+1]
list year month praise_pct praise_pct_lag



************
* analyses * 
************

****** tweets ******
sum praise_pct if year==2017
sum praise_pct if year==2018
sum praise_pct if year==2019
sum praise_pct if mocount<48 & mocount>36

sum attack_bias_pct if year==2017
sum attack_bias_pct if year==2018
sum attack_bias_pct if year==2019
sum attack_bias_pct if mocount<48 & mocount>36


****** checking for heterosked ******
reg fncprimetime_change attack_bias_pct_lag jan feb mar apr may jun jul aug sep oct nov time timesquared

predict resid, residuals
list resid 
sktest resid
hettest resid 
   

****** mean annual ratings ******
sum fncprimetimeratings811p if year==2017
sum fncprimetimeratings811p if year==2018
sum fncprimetimeratings811p if year==2019
sum fncprimetimeratings811p if year==2020

sum fnctotaldayviewers if year==2017
sum fnctotaldayviewers if year==2018
sum fnctotaldayviewers if year==2019
sum fnctotaldayviewers if year==2020

sum fncprimetimeratings811p 

****** models for Table 1 ******

** PRIMETIME **
sum attack_bias_pct_lag

reg fncprimetimeratings811p attack_bias_pct_lag time timesquared fncprimetime_lag jan feb mar apr may jun jul aug sep oct nov , robust
di -22450.57 *12.01297  //one sd in % attacks: drop in ratings of -269698

reg fncprimetimeratings811p attack_bias_pct_lag time timesquared fncprimetime_lag msnbcprimetimeratings cnnprimetimeratings jan feb mar apr may jun jul aug sep oct nov , robust

** DAYTIME **

reg fnctotaldayviewers attack_bias_pct_lag time timesquared fncdaytime_lag jan feb mar apr may jun jul aug sep oct nov, robust

reg fnctotaldayviewers attack_bias_pct_lag time timesquared fncdaytime_lag msnbctotaldayviewers cnntotaldayviewers jan feb mar apr may jun jul aug sep oct nov, robust


****** models for appendix ******

// change DV

** PRIMETIME **
reg fncprimetime_change attack_bias_pct_lag time timesquared jan feb mar apr may jun jul aug sep oct nov, robust
sum attack_bias_pct_lag

reg fncprimetime_change attack_bias_pct_lag time timesquared cnnprimetime_change msnbcprimetime_change jan feb mar apr may jun jul aug sep oct nov, robust

** DAYTIME **
reg fncdaytime_change attack_bias_pct_lag time timesquared jan feb mar apr may jun jul aug sep oct nov, robust

reg fncdaytime_change attack_bias_pct_lag time timesquared cnndaytime_change msnbcdaytime_change jan feb mar apr may jun jul aug sep oct nov, robust


// IV not lagged 

** PRIMETIME **
reg fncprimetimeratings811p attack_bias_pct time timesquared fncprimetime_lag jan feb mar apr may jun jul aug sep oct nov, robust

** DAYTIME **
reg fnctotaldayviewers attack_bias_pct time timesquared fncdaytime_lag jan feb mar apr may jun jul aug sep oct nov , robust

// control for and drop 2017: ailes left in 2016; bill o'reilly left april 2017; megyn kelly left in jan 2017

* control for 2017
** PRIMETIME **
reg fncprimetimeratings811p attack_bias_pct_lag time timesquared fncprimetime_lag jan feb mar apr may jun jul aug sep oct nov yr2017, robust

reg fncprimetimeratings811p attack_bias_pct_lag time timesquared fncprimetime_lag msnbcprimetimeratings cnnprimetimeratings jan feb mar apr may jun jul aug sep oct nov yr2017, robust

** DAYTIME **
reg fnctotaldayviewers attack_bias_pct_lag time timesquared fncdaytime_lag jan feb mar apr may jun jul aug sep oct nov yr2017, robust

reg fnctotaldayviewers attack_bias_pct_lag time timesquared fncdaytime_lag msnbctotaldayviewers cnntotaldayviewers jan feb mar apr may jun jul aug sep oct nov yr2017, robust

* drop 2017
** PRIMETIME **
reg fncprimetimeratings811p attack_bias_pct_lag time timesquared fncprimetime_lag jan feb mar apr may jun jul aug sep oct nov if year!=2017, robust

reg fncprimetimeratings811p attack_bias_pct_lag time timesquared fncprimetime_lag msnbcprimetimeratings cnnprimetimeratings jan feb mar apr may jun jul aug sep oct nov if year!=2017, robust

** DAYTIME **
reg fnctotaldayviewers attack_bias_pct_lag time timesquared fncdaytime_lag jan feb mar apr may jun jul aug sep oct nov if year!=2017, robust

reg fnctotaldayviewers attack_bias_pct_lag time timesquared fncdaytime_lag msnbctotaldayviewers cnntotaldayviewers jan feb mar apr may jun jul aug sep oct nov if year!=2017, robust


// appearance IVs

** PRIMETIME **
reg fncprimetimeratings811p appearance_pct_lag time timesquared fncprimetime_lag jan feb mar apr may jun jul aug sep oct nov , robust

** DAYTIME **
reg fnctotaldayviewers appearance_pct_lag time timesquared fncdaytime_lag jan feb mar apr may jun jul aug sep oct nov , robust
